package com.db.dao;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import org.apache.commons.dbutils.QueryRunner;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

public class JJRDao extends BaseDAO{
	
	// 单例模式 start
			private volatile static JJRDao instance = null;
			
			
			private JJRDao() throws SQLException {
				super();

			}
			public static JJRDao getInstance() throws SQLException {
				if (instance == null) {
					synchronized (JJRDao.class) {// 1
						if (instance == null) {// 2
							instance = new JJRDao();// 3
						}
					}
				}
				return instance;
			}
			// 单例模式 end
	



	//qr dataSource connection 实例化
	@Override
	void init() throws SQLException {
		// TODO Auto-generated method stub  db_two
		
		Resource resource = new ClassPathResource("database.xml"); 
		BeanFactory factory = new XmlBeanFactory(resource); 
		
		this.setQr(new QueryRunner());
		this.setDataSource((DataSource)factory.getBean("db_one"));
		this.setConnection(this.getDataSource().getConnection());
		
	}
	
	public static void main(String[] args){
		
	}

}
